<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------

/**
 * Class EmergencyContact
 * Desc  紧急联系人Model
 * Create on 2024/10/24 14:41
 * Create by wangyafang
 */
namespace app\api\model\wddj\user;

use addons\wddj\library\IDCardEncryptor;
use think\Model;

class UserRealNameAuthentication extends Model
{
// 表名
    protected $name = 'wddj_user_real_name_authentication';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    public function getNameAttr($value)
    {
        return $this->replaceCharacters($value);
    }

    public function getIdCardAttr($value)
    {
        $configObj = (new \app\api\model\wddj\Config())->get(1);
        $encryptor = new IDCardEncryptor($configObj['encryptor_key'],$configObj['encryptor_iv']);
        $value = $encryptor->decrypt($value);
        return substr_replace($value, '**********', 6,10);
    }

    //第一个字符不变，其他显示成*
    private function replaceCharacters($string) {
        // 获取字符串的第一个字符
        $firstChar = mb_substr($string, 0, 1);
        // 获取字符串的剩余部分
        $remainingChars = mb_substr($string, 1);
        // 用 * 替换剩余部分的字符
        $maskedChars = str_repeat('*', mb_strlen($remainingChars));
        // 返回结果
        return $firstChar . $maskedChars;
    }



}



 